package com.zhangyx.crawler.core.browser;

import com.zhangyx.crawler.comm.PropertiesUtil;
import org.apache.log4j.Logger;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class BrowserUtil {
    private static Logger log = Logger.getLogger(BrowserUtil.class);
    private static ChromeDriver driverProxy;

    public static ChromeDriver createChromeDriver() {
       return createChromeDriver(null);
    }

    public static ChromeDriver createChromeDriver(ChromeOptions options) {
        String driverPath = PropertiesUtil.get("webdriver.chrome.driver");
        if (driverPath == null) {
            log.error("必须在properties配置webdriver.chrome.driver（chromedriver文件的位置），否则无法启动");
            return null;
        }
        System.setProperty("webdriver.chrome.driver", driverPath);
        if (options != null) {
            return new ChromeDriver(options);
        }
        return new ChromeDriver();
    }

}

